<template>
  <div class="login-container">
    <el-form
      ref="orderFormRef"
      :model="orderForm"
      :rules="orderRules"
      class="login-form"
    >
      <div class="flex text-white items-center py-4">
        <span class="text-2xl flex-1 text-center">UE像素流接口调试工具</span>
      </div>

      <el-form-item prop="appid">
        <div class="p-2 text-white">
          <svg-icon icon-class="user" />
        </div>
        <el-input
          class="flex-1"
          ref="appid"
          size="large"
          v-model="orderForm.appid"
          :placeholder="请输入应用id"
          name="appid"
        />
      </el-form-item>
	  
	  <el-form-item prop="url">
	    <div class="p-2 text-white">
	      <svg-icon icon-class="user" />
	    </div>
	    <el-input
	      class="flex-1"
	      ref="url"
	      size="large"
	      v-model="orderForm.url"
	      :placeholder="请输入渲染地址"
	      name="url"
	    />
	  </el-form-item>
	  
      <el-button
        size="default"
        :loading="loading"
        type="primary"
        class="w-full"
        @click.prevent="handleLogin"
        >
		启功渲染
      </el-button>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import router from "@/router";
import SvgIcon from "@/components/SvgIcon/index.vue";

// API依赖
import {useRoute } from "vue-router";
import { Order } from "@/vo";
const route = useRoute();

const loading = ref(false);

const orderFormRef = ref(ElForm);
const orderForm = ref<Order>({
  appid: "1",
  url: "http://127.0.0.1:8880"
});

const orderRules = {
  appid: [{ required: true, trigger: "blur" }],
  url: [{ required: true, trigger: "blur", validator: passwordValidator }]
};

function passwordValidator(rule: any, value: any, callback: any) {
  if (value.length < 6) {
    callback(new Error("The password can not be less than 6 digits"));
  } else {
    callback();
  }
}

function handleLogin() {
  orderFormRef.value.validate((valid: boolean) => {
    if (valid) {
		router.push({ path: '/', query:orderForm.value});
    }
  });
}
onMounted(() => {
});
</script>

<style lang="scss" scoped>
.login-container {
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background-color: #2d3a4b;

  .login-form {
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;

    .captcha {
      position: absolute;
      top: 0;
      right: 0;

      img {
        width: 120px;
        height: 48px;
        cursor: pointer;
      }
    }
  }
}

.el-form-item {
  background: rgb(0 0 0 / 10%);
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 5px;
}

.el-input {
  background: transparent;

  // 子组件 scoped 无效，使用 :deep
  :deep(.el-input__wrapper) {
    padding: 0;
    background: transparent;
    box-shadow: none;

    .el-input__inner {
      color: #fff;
      background: transparent;
      border: 0;
      border-radius: 0;
      caret-color: #fff;

      &:-webkit-autofill {
        box-shadow: 0 0 0 1000px transparent inset !important;
        -webkit-text-fill-color: #fff !important;
      }

      // 设置输入框自动填充的延迟属性
      &:-webkit-autofill,
      &:-webkit-autofill:hover,
      &:-webkit-autofill:focus,
      &:-webkit-autofill:active {
        transition: color 99999s ease-out, background-color 99999s ease-out;
        transition-delay: 99999s;
      }
    }
  }
}
</style>
